﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

//Write a program that fills and prints a matrix of size (n, n) as shown below: (examples for n = 4)

namespace MatrixB
{
    class MatrixB
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Please enter the size of the Matrix, Neo!");
            Console.Write("Neo: ");
            int n = int.Parse(Console.ReadLine());
            int [,] matrix = new int [n,n];
            int fillValue = 1;

            for (int col = 0; col < matrix.GetLength(0); col++)
            {
                if (col % 2 == 0)
                {
                    for (int row = 0; row < matrix.GetLength(0); row++)
                    {
                        matrix[row, col] = fillValue;
                        fillValue++;
                    }
                }
                else 
                {
                    for (int row = matrix.GetLength(0) - 1; row >=0; row--)
                    {
                        matrix[row, col] = fillValue;
                        fillValue++;
                    }
                }
            }

            // Print the Matrix
            for (int row = 0; row < matrix.GetLength(0); row++)
            {
                for (int col = 0; col < matrix.GetLength(1); col++)
                {
                    Console.Write("{0,4}", matrix[row, col]);
                }
                Console.WriteLine();
            }
        }
    }
}
